﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TPLOAWebService.Models
{
    public class StaffRepository : IStaffRepository
    {
        public IEnumerable<Staff> GetAll()
        {
            return TPLOADBManager.GetAllStaff().Cast<Staff>();
        }

        public Staff Get(string id)
        {
            return TPLOADBManager.GetStaffByID(id);
        }

        public Staff Add(Staff item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (TPLOADBManager.InsertStaff(item) == 0)
            {
                return null;
            }
            else
            {
                return item;
            }
        }

        public void Remove(string id)
        {
            TPLOADBManager.DeleteStaff(id);
        }

        public bool Update(Staff item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (TPLOADBManager.UpdateStaff(item) == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}